
<h3><?php echo $this->lang->line("update_list_fly");?></h3>
<style>
    .fone_num_cls{
        width:15%;  vertical-align: top;
    }
    .navbar-inverse{
        display: none;
    }
    body{
        padding-top:10px;
        padding-bottom:30px;
    }
</style>

<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" flyTomorrow-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //phone
                echo form_label($this->lang->line('phone'), 'phone');
                echo form_input(array('readonly' => 'true', 'name' => 'phone', 'id' => 'phone', 'value' =>$phone,'class'=>'fone_num_cls')).' ';
                echo form_button(array('id'=>'phone_callback','value' => '3', 'name' => 'callback', 'content' => $this->lang->line('phone_callback'),'class' => 'btn btn-success')).' ';
                echo form_button(array('id'=>'phone_callok','value' => '4', 'name' => 'callok', 'content' => $this->lang->line('phone_callok'),'class' => 'btn btn-success')).' ';
                echo form_input(array('type'=>'hidden', 'name' => 'phone_callstatus', 'id' => 'phone_callstatus', 'value' =>''));
                echo form_error('phone');
                //hanh trinh khach hoi
                echo form_label($this->lang->line('listship'), 'ship');
                echo form_textarea(array('name' => 'ship', 'id' => 'ship', 'value' => $lists[0]->note_customers,'rows'=>'5','readonly'=>'true'));
                echo form_error('ship');
                //Ghi chú sale
                echo form_label($this->lang->line('note'), 'note');
                echo form_textarea(array('name' => 'note', 'id' => 'note', 'value' => '','rows'=>'5'));
                echo form_error('note');
                //HIDDEN
                echo form_input(array('type'=>'hidden', 'name' => 'salesID', 'id' => 'salesID', 'value' =>$salesID));
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <?php echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'parent.jQuery.fancybox.close()')); ?>
                <span id="loads"></span>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<script>
$(document).ready(function() {
    $('button[type="submit"]').attr('disabled','disabled');
    $( "#phone_callback" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-danger";
        document.getElementById("phone_callok").className           = "btn btn-success";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callok').attr('disabled','disabled');

    });

    $( "#phone_callok" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-success";
        document.getElementById("phone_callok").className           = "btn btn-danger";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callback').attr('disabled','disabled');
    });
    
    $("#submit").on('click',function(e){
            $('button[type="submit"]').attr('disabled','disabled');
            $("#loads").html('<img width="3%" src="<?php echo STATIC_URL;?>backend/images/icon/loading-2.gif" /> vui lòng chờ ...');
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/listship/call_post/',
                        type: "POST",
                        data : {phone:$("#phone").val(),phone_callstatus:$("#phone_callstatus").val(),note:$("#note").val(),salesID:$("#salesID").val()},
                        cache: false,
                        beforeSend: function(){
                            $("#loads").html('<img width="3%" src="<?php echo STATIC_URL;?>backend/images/icon/loading-2.gif" />  đang xử lí ...');
                        },
                        success:function(data)
                        {
                            setTimeout(function () {
                                if(data==0){
                                    $("#loads").html("<?php echo $this->lang->line("update_successful");?>");
                                    setTimeout(function () {
                                        parent.jQuery.fancybox.close();
                                    },1000);
                                } else {
                                    $('button[type="submit"]').removeAttr('disabled');
                                    $("#loads").html("Thao tác thất bại!");
                                }
                            }, 2000);
                        },
                        error: function() 
                        {
                            alert("Lỗi! Contact Admin!");
                        }
                    });
            }, 2000);
            e.preventDefault();	//STOP default action
    });
    
    
});
</script>